package com.e3.web.widget.client;

import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;


public abstract class MyRefDialog<D> extends MyDialog {
	
	private MyRefTextField<D> refField;
	
	public MyRefDialog(){
		this.addListener(Events.Show, new Listener<ComponentEvent>(){

			public void handleEvent(ComponentEvent be) {
				onRefWindowShow();
			}
			
		});
	}
	
	public void setRefTextField(MyRefTextField<D> refField){
		this.refField = refField;
	}
	
	public MyRefTextField<D> getRefTextField(){
		return this.refField;
	}
	
	public abstract void setRefValue(D value);
	
	public abstract D getRefValue();
	
	public abstract void onRefWindowShow();

	@Override
	protected void onOk() {
		String s = getDisplayValue();
		getRefTextField().setValue(s);
		this.setVisible(false);
	}
	
	public String getDisplayValue() {
		Object value = getRefValue();
		if(value==null){
			return "";
		}
		return value.toString();
	}
}
